/*
 * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.matezk.dms.things.model.req;

import cn.hutool.core.util.ObjectUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import top.continew.starter.extension.crud.model.req.BaseReq;

import java.io.Serial;

/**
 * 创建或修改设备参数
 *
 * @author 程道林
 * @since 2024/12/02 10:59
 */
@Data
@Schema(description = "创建或修改设备参数")
public class DeviceReq extends BaseReq {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 设备ID
     */
    @Schema(description = "设备ID")
    @NotBlank(message = "设备ID不能为空")
    @Length(max = 36, message = "设备ID长度不能超过 {max} 个字符")
    private String deviceId;

    /**
     * 别名
     */
    @Schema(description = "别名")
    @NotBlank(message = "别名不能为空")
    @Length(max = 30, message = "别名长度不能超过 {max} 个字符")
    private String aliasName;

    /**
     * 组织ID
     */
    @Schema(description = "组织ID")
    @NotNull(message = "组织ID不能为空")
    private Long deptId;

    /**
     * 工作模式
     */
    @Schema(description = "工作模式")
    @NotNull(message = "工作模式不能为空")
    private Integer mode;

    public String getProductId() {
        return ObjectUtil.isEmpty(deviceId) ? "" : deviceId.split("/")[0];
    }

    public String getDeviceName() {
        return ObjectUtil.isEmpty(deviceId) ? "" : deviceId.split("/")[1];
    }
}